package com.example.dotatrivia;

import java.io.IOException;
import java.io.InputStream;

import entities.Hero;
import Adapters.HeroAdapter;
import Adapters.ImageAdapter;
import android.app.Activity;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.Toast;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
    	try {
    	super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        AssetManager am = getApplicationContext().getAssets();
    	InputStream in;
		
			in = am.open(Hero.xmlFileName);

        Hero h = new Hero(in);
        GridView gridview = (GridView) findViewById(R.id.gridView1);
        gridview.setAdapter(new HeroAdapter(getApplicationContext(), Hero.getHeroes()));

        gridview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();
            }
        });
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
    //--------
 
  /*  
    public void buttonClicked(View view) throws IOException, XmlPullParserException  {

    	AssetManager am = view.getContext().getAssets();
    	InputStream in = am.open(Fact.xmlFileName);
    	Fact f = new Fact(in);
    	f = Fact.getARandomFact();
    	    	
    	AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());    	
    	   	
    	String[] nls = view.getResources().getStringArray(R.array.nls);
    	   	
		builder.setMessage(nls[f.getId()]).setTitle(R.string.dialog_title);
    	
    	AlertDialog dialog = builder.create();
  	
    	dialog.show();
    	


    }
      
*/
    

}
